package some.list.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import some.list.dao.AllListDao;
import some.list.domain.ProfilCommand;
import some.member.profil.dao.IdealMemberDao;
import some.member.profil.domain.IdealMemberCommand;

@Component
public class RecommendList {
	
	@Autowired
	private AllListDao allListDao;
	@Autowired
	private IdealMemberDao idealMemberDao;
	
	public List<ProfilCommand> Recommendprocess(String id){
		
		IdealMemberCommand myIdeal = idealMemberDao.getIdealMember(id);
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", id);
		map.put("home", "");
		map.put("age", "");
		map.put("height", "");
		map.put("bodyty", "");
		map.put("start", "");
		map.put("end", "");
		List<ProfilCommand> list = allListDao.list(map);
		
		List<ProfilCommand> recommandList = new ArrayList<ProfilCommand>();
		
		int match;
		int age;
		int height;
		for(int i=0; i<list.size(); i++){
			match=0;
			
			age = list.get(i).getAge();
			if(age<=15){
				age=1;
			}else if(age>=16 && age<=20){
				age=16;
			}else if(age>=21 && age<=25){
				age=21;
			}else if(age>=26 && age<=30){
				age=26;
			}else if(age>=31 && age<=35){
				age=31;
			}else if(age>=36 && age<=40){
				age=36;
			}else
				age=41;
			
			if(age == myIdeal.getAge())
				match++;
			if(list.get(i).getHome().equals(myIdeal.getHome()))
				match++;
			
			height = list.get(i).getHeight();
			if(height<=150){
				height=150;
			}else if(height>=151 && height<=155){
				height=151;
			}else if(height>=156 && height<=160){
				height=156;
			}else if(height>=161 && height<=165){
				height=161;
			}else if(height>=166 && height<=170){
				height=166;
			}else if(height>=171 && height<=175){
				height=171;
			}else if(height>=176 && height<=180){
				height=176;
			}else
				height=181;
						
			if(height == myIdeal.getHeight())
				match++;
			if(list.get(i).getBodyty().equals(myIdeal.getBodyty()))
				match++;
			if(list.get(i).getCharac().equals(myIdeal.getCharac()))
				match++;
			if(match>2)
				recommandList.add(list.get(i));
		}
		
		return recommandList;
	}
}
